###Controlling graph size in RMarkdown
library(tidyverse)
SNPs<- read.table("23andMe_complete.txt", header = TRUE, sep = "\t")
SNPs$chromosome = ordered(SNPs$chromosome, levels=c(seq(1, 22), "X", "Y", "MT"))
ggplot(data = SNPs) +
geom_bar(mapping = aes(x = genotype, fill = chromosome)) +
coord_polar() +
ggtitle("Total SNPs for each genotype") +
ylab("Total number of SNPs") +
xlab("Genotype")
###Graphic Output
pdf("SNP_example_plot.pdf", width=6, height=3)
ggplot(data = SNPs) +
geom_bar(mapping = aes(x = chromosome, fill = genotype))
dev.off()
## quartz_off_screen
## 2
ppi <- 300
png("SNP_example_plot.png", width=6*ppi, height=6*ppi, res=ppi)
ggplot(data = SNPs) +
geom_bar(mapping = aes(x = chromosome, fill = genotype))
dev.off()
## quartz_off_screen
## 2
###R-Markdown Loading Images
###Interactive graphs and tables in RMarkdown reports
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <- ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point()
ggplotly(p)
library(plotly)
ggplotly(
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point()
)
library(DT)
datatable(iris)
###Exercise 1
SNPs<- read.table("23andMe_complete.txt", header = TRUE, sep = "\t")
str (SNPs)
## 'data.frame': 960614 obs. of 4 variables:
## $ rsid : Factor w/ 960614 levels "i1000009","i2000003",..: 600125 532383 535928 178265 124446 723988 655510 600036 813048 254468 ...
## $ chromosome: Factor w/ 25 levels "1","10","11",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ position : int 82154 752566 752721 776546 798959 800007 838555 846808 854250 861808 ...
## $ genotype : Factor w/ 20 levels "--","A","AA",..: 3 3 15 5 5 8 4 10 5 15 ...
p<- ggplot(SNPs,aes(x = chromosome, fill = chromosome ))
p + geom_bar(fill="blue")+ xlab("Chromosomes") + ylab("Number of SNPs") + ggtitle("Total SNPs per Chromosome")
###Exercise 2
SNPs$chromosome = ordered(SNPs$chromosome, levels=c(seq(1, 22), "X", "Y", "MT"))
x<-c("AA"="green","A"="blue","AC"="green","AG"="green","AT"= "green","CG"="green","CC"="green", "C"="blue", "CT"="green","GG"="green", "GT"="green", "G"="blue", "TT"="green","T"="blue","--"="orange","D"="orange","DI"= "orange","DD"="orange", "I"="orange", "II"="orange")
p<- ggplot(SNPs,aes(x = chromosome, fill = genotype ))
p + geom_bar(color = "black")+ xlab("Chromosomes") + ylab("Number of SNPs per Genotypes") + ggtitle("Total Genotypes per Chromosome") + scale_fill_manual(values=c(x))
###Exercise 3
ppi<-300
png("SNP_example_plot.png", width=6*ppi, height=6*ppi, res=ppi)
p<- ggplot(SNPs,aes(chromosome, fill = genotype ))
p + geom_bar ( position= "dodge")+ xlab("Chromosomes") + ylab("Number of SNPs per Genotypes") + ggtitle("Total Genotypes per Chromosome")
dev.off()
## quartz_off_screen
## 2
###Exercise 4
SNPs$chromosome = ordered(SNPs$chromosome, levels=c(seq(1, 22), "X", "Y", "MT"))
p<- ggplot(SNPs,aes( chromosome, fill = genotype ))
p + geom_bar (position= "dodge") +
facet_wrap(~genotype, ncol= 2)+ xlab("Chromosomes") + ylab("Genotype Abundance") + ggtitle("Total Genotypes per Chromosome")+theme(plot.title = element_text(hjust = 5))
###Exercise 5
library(plotly)
SNPs$chromosome = ordered(SNPs$chromosome, levels=c(seq(1, 22), "X", "Y", "MT"))
p<- ggplot(SNPs,aes( chromosome, fill = genotype )) + geom_bar (position= "dodge") +
facet_wrap(~genotype, ncol= 2)+ xlab("Chromosomes") + ylab("Genotype Abundance") + ggtitle("Total Genotypes per Chromosome")+theme(plot.title = element_text(hjust = 5))
ggplotly(p)
Exercise #6
library(DT)
Y<-subset(SNPs, chromosome == "Y")
datatable(Y)
## Warning in instance$preRenderHook(instance): It seems your data is too big
## for client-side DataTables. You may consider server-side processing: https://
## rstudio.github.io/DT/server.html